﻿Imports System.Data
Imports System.Data.SqlClient
Public Class Frm_Type_Travail
    Public Sub Afficher()
        Try
            List_Catégorie.Items.Clear()
            Cmd = New SqlCommand("Select * From Comb_Categ_Personnels", Con)
            open()
            Dr = Cmd.ExecuteReader()
            Do While Dr.Read()
                Dim Line As ListViewItem = New ListViewItem(New String() {Dr("Categorie")})
                List_Catégorie.Items.Add(Line)
            Loop
            Dr.Close()
            cnClose()
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Exclamation)
            cnClose()
        End Try
    End Sub
    Private Sub Frm_Type_Travail_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
        Frm_Gestion_Personnels.Enabled = True
        Frm_Gestion_Personnels.Comb_catégori()
    End Sub

    Private Sub Frm_Type_Travail_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Frm_Gestion_Personnels.Enabled = False
        txt_Catégorie.Select()
        Afficher()
    End Sub

    Private Sub btn_ajouter_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_ajouter.Click
        If (txt_Catégorie.Text <> "") Then
            Try
                Cmd = New SqlCommand("insert into Comb_Categ_Personnels (Categorie) values (@vil)", Con)

                Cmd.Parameters.Add("@vil", SqlDbType.VarChar).Value = txt_Catégorie.Text
                open()
                Cmd.ExecuteNonQuery()
                cnClose()

                Afficher()
                txt_Catégorie.Clear()
                txt_Catégorie.Select()
            Catch ex As Exception
                MsgBox(ex.Message, MsgBoxStyle.Exclamation)
                cnClose()
            End Try
        End If
    End Sub

    Private Sub btn_supp_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_supp.Click
        Dim vil As String = ""
        With List_Catégorie
            If .SelectedIndices.Count > 0 Then
                For i As Integer = 0 To .SelectedIndices.Count - 1
                    vil = .Items(.SelectedIndices(i)).SubItems(0).Text
                Next

                Try
                    Cmd = New SqlCommand("Delete From Comb_Categ_Personnels Where Categorie = '" & vil & "'", Con)
                    open()
                    Cmd.ExecuteNonQuery()
                    cnClose()

                    Afficher()
                    txt_Catégorie.Clear()
                    txt_Catégorie.Select()
                Catch ex As Exception
                    MsgBox(ex.Message, MsgBoxStyle.Exclamation)
                    cnClose()
                End Try
            End If
        End With
    End Sub
End Class